package com.wsd.jing.auth;

import cn.dev33.satoken.stp.StpInterface;
import com.wsd.jing.mapper.MenuMapper;
import com.wsd.jing.mapper.RoleMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * All rights Reserved, Designed By www.tom.com
 *
 * @author tom
 * @version 1.0.0
 * @projectName: jing
 * @packageName: com.wsd.jing.config
 * @className: SaAuthConfig
 * @description SaToken鉴权配置
 * @createDate 2022/11/17 22:25
 * @copyright 2022/11/17 22:25 www.tom.com Inc. All rights reserved.
 */
@Component
@AllArgsConstructor
@Slf4j
public class SaAuthConfig implements StpInterface {

    private final MenuMapper menuMapper;
    private final RoleMapper roleMapper;

    /**
     * @param loginId:账号id，即你在调用StpUtil.login(id) 时写入的标识值
     * @param loginType:账号体系标识，此处可以暂时忽略，多账户认证时需要
     * @return List<String>
     * @author tom
     * @description 设置当前用户操作权限
     * @createDate 2022/11/18 11:54
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        List<String> permissionList = menuMapper.listPermissions(Integer.parseInt(loginId.toString()));
        return permissionList;
    }

    /**
     * @param loginId:账号id，即你在调用StpUtil.login(id) 时写入的标识值
     * @param loginType:账号体系标识，此处可以暂时忽略，多账户认证时需要
     * @return List<String>
     * @author tom
     * @description 设置当前用户角色权限
     * @createDate 2022/11/18 11:55
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<String> roleList = roleMapper.listRoles(Integer.parseInt(loginId.toString()));
        return roleList;
    }
}
